/* 将"  I  am  good student.  "变为"I am good student.      " */

#include <stdio.h>

int main()
{
    char buffer[] = "  I    am    good  student.  ";
    int len = sizeof(buffer) / sizeof(char);
    // printf("len = %d\n", len);
    // for (int idx = 0; idx < len; idx++)
    // {
    //     printf("buffer[%d] = %d\n", idx, buffer[idx]);
    // }

    for (int idx = 0; idx < len - 1; idx++)
    {
        if (buffer[idx] - buffer[idx + 1] > 0)
        {
            if(buffer[idx + 1] == ' ' && buffer[idx + 2] == ' ')
            {
                for (int jdx = idx + 1; jdx < len - 1; jdx++)
                {
                    buffer[jdx] = buffer[jdx + 1];
                }
                idx--;
            }
        }
        // printf("buffer:%s\n", buffer);
    }
    // printf("buffer:%s\n", buffer);

    do
    {
        for (int idx = 0; idx < len; idx++)
        {
            buffer[idx] = buffer[idx + 1];
        }  
    } while (buffer[0] == ' ');
    printf("buffer:%s\n", buffer);

    // for (int idx = 0; idx < len; idx++)
    // {
    //     printf("buffer[%d] = %d\n", idx, buffer[idx]);
    // }
}